﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NN
{
    public partial class SimulationControl : System.Windows.Forms.UserControl

    {
        double InputValue;
        public event EventHandler ValueChanged;
        public SimulationControl()
        {
            InitializeComponent(); 
            textBox1.Location = new System.Drawing.Point(170, 20);
            textBox1.Size = new System.Drawing.Size(100, 20);
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            trackBar1.Value = System.Convert.ToInt32(textBox1.Text);
            InputValue = System.Convert.ToDouble(textBox1.Text);
        }

        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            textBox1.Text = trackBar2.Value.ToString();
            InputValue = trackBar2.Value;
        }
        public string Label
        {
            get { return label2.Text; }
            set { label2.Text = value; }
        }
        public int Max
        {
            get { return trackBar2.Maximum; }
            set { trackBar2.Maximum = value; }
        }
        public int Min
        {
            get { return trackBar2.Minimum; }
            set { trackBar2.Minimum = value; }
        }
        public double Value 
        {
            get { return InputValue; }
            set { InputValue = value;  textBox2.Text = value.ToString(); } 
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            double temp = -1;
            try 
            { 
                temp = double.Parse(textBox2.Text);
                if (temp > trackBar2.Maximum)
                {
                    trackBar2.Value = trackBar2.Maximum;
                }
                else if (temp < trackBar2.Minimum)
                {
                    trackBar2.Value=trackBar2.Minimum;
                }
                else
                {
                    trackBar2.Value = (int)temp;
                }

                InputValue = temp;
                //InputValue = System.Convert.ToDouble(textBox2.Text);
                ValueChanged(this, null);
            }
            catch
            {
                MessageBox.Show("Inproper Input");
            }
            
        }

        private void trackBar2_Scroll(object sender, EventArgs e)
        {
            textBox2.Text = trackBar2.Value.ToString();
            InputValue = trackBar2.Value;
            ValueChanged(this,null);
        }
        

    }
}
